/**
 * 
 */
package org.ccnetconfig.ccdroid;

import java.util.LinkedList;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author Ryan
 * 
 */
public class ServerAdapter extends BaseAdapter {
	private Context								context		= null;
	private LinkedList<Settings>	settings	= null;

	public ServerAdapter ( Context context, LinkedList<Settings> settings ) {
		this.setContext ( context );
		this.setSettings ( settings );
	}

	public int getCount ( ) {
		return this.getSettings ().size ();
	}

	public Settings getItem ( int position ) {
		return this.getSettings ().get ( position );
	}

	public long getItemId ( int position ) {
		return this.getSettings ().get ( position ).getId ();
	}

	public View getView ( int position, View convertView, ViewGroup parent ) {
		if ( convertView != null ) {
			return (TextView) convertView;
		} else {
			AbsListView.LayoutParams lp = new AbsListView.LayoutParams ( ViewGroup.LayoutParams.FILL_PARENT, 64 );

			TextView textView = new TextView ( this.getContext () );
			textView.setLayoutParams ( lp );
			// Center the text vertically
			textView.setGravity ( Gravity.CENTER_VERTICAL | Gravity.LEFT );
			// Set the text starting position
			textView.setPadding ( 36, 0, 0, 0 );
			textView.setText ( this.getItem ( position ).getHost () );
			return textView;
		}
	}

	/**
	 * @param context
	 *          the context to set
	 */
	private void setContext ( Context context ) {
		this.context = context;
	}

	/**
	 * @return the context
	 */
	public Context getContext ( ) {
		return context;
	}

	/**
	 * @param settings
	 *          the settings to set
	 */
	private void setSettings ( LinkedList<Settings> settings ) {
		this.settings = settings;
	}

	/**
	 * @return the settings
	 */
	public LinkedList<Settings> getSettings ( ) {
		return settings;
	}

}
